<?php

if (!defined("MCTDESIGN")) die("# ");
$id = (int)$id;
global $anyDB;
$temp_news = $temp;
$temp_news->assign( 'base_tpl', "".$dir_tpl."" );
if ($act == 'category') {
	

	$temp_news->assign( 'base_tpl', "".$dir_tpl."" );
    // get lis bài viêt phân trang 
    $pagegroup_size = 10;
    $page=_POST('p');
    if (!$page||$page==0){$page=1;}
    $limit=_POST('limit');
    if($limit==''||$limit>30) {$limit=12;}
    $offset=($page-1)*$limit;
    $li="limit $offset,$limit";
    //dem so ban gi 
    $sql ="Select COUNT(sid) as tongbanghi,title,sid,time,content_desc from ".$tb_fix."_news_post where catpid = 7";
    $q = $anyDB->query($sql);
    $arr = $anyDB->getNext($q);
    $totalRecord = $arr['tongbanghi']; // tong so ban ghi
    // end khai bao phan trang
    // get data theo phan trang 
    $sql = "select * from ".$tb_fix."_news_post  where catpid = 7 ORDER BY sid DESC $li";
    $q = $anyDB->query($sql);
    $arr = $anyDB->getAll($q);
    foreach ($arr as $key => $value){
        $arr[$key]['ngaythang']= date('d/m/Y-h:i:s', $value['time']);
        $arr[$key]['title_conver'] = convertText($value['title']); 
        $arr[$key]['title_cut'] = subCutString($value['content_desc'],20);
    }
    //echo "<pre>"; print_r($arr); die();
    $temp_news->assign('datatin',$arr);
    $pages = pagenavigator($page,$totalRecord,$limit,$pagegroup_size,"LamHoChieuVisa.html/");
    $temp_news->assign('pading',$pages);

	$content = $temp_news->fetch( 'modules/_lamhochieu.mct' );
}
else if ($act=='viewpost') {
        $id =  isset($_GET['id']) ? intval(stripslashes(urldecode($_GET["id"]))) : '';
        if(empty($id)){
            header("Location: home.html");
        }else{
            
            $sql = "select * from ".$tb_fix."_news_post where sid = $id ";
            $q = $anyDB->query($sql);
            $arr = $anyDB->getNext($q);
            $temp_news->assign('chitiet',$arr);
            $temp_news->assign('ngayviet', date('d/m/Y-h:i:s', $arr['time']));
            $temp_news->assign('titile_conver',convertText($arr['title']));
            $temp_news->assign('titile',$arr['title']);
            $temp_news->assign('noidung',$arr['content']);  
            // echo $arr['content']; die();      
            
            // get 7 tin lên quan

            $sql = "SELECT title, sid, time FROM  ".$tb_fix."_news_post WHERE sid !=$id AND catid =7 ORDER BY RAND( ) LIMIT 6";
            $q = $anyDB->query($sql);
            $arrlienquan = $anyDB->getAll($q);
            foreach ($arrlienquan as $key => $value){
                $arrlienquan[$key]['ngaythang']= date('d/m/Y-h:i:s', $value['time']);
                $arrlienquan[$key]['title_conver'] = convertText($value['title']); 
               
            }
            $temp_news->assign('tinlienquan',$arrlienquan);
            $content = $temp_news->fetch( 'modules/_lamhochieu.mct' );            
        }

}
else  {
    header("Location: home.html");
}

?>